package cn.wolfcode.luowowo.website.controller;

import cn.wolfcode.luowowo.article.domain.Destination;
import cn.wolfcode.luowowo.article.service.IDestinationService;
import cn.wolfcode.luowowo.common.util.AjaxResult;
import cn.wolfcode.luowowo.flight.domain.Flight;
import cn.wolfcode.luowowo.service.IFlightService;
import cn.wolfcode.luowowo.website.util.FlightUtil;
import com.alibaba.fastjson.JSON;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.dubbo.remoting.transport.dispatcher.message.MessageOnlyDispatcher;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.awt.geom.RectangularShape;
import java.util.List;

@Controller
@RequestMapping("/flight")
public class FlightController {

    @Reference
    private IFlightService flightService;

    @RequestMapping("/index")
    public String index(Model model){

        //hotFlights
        List<Flight> hotFlights =  flightService.listIsHot();
        model.addAttribute("hotFlights",hotFlights);
        //initialA
        List<Flight> initialA = flightService.listLetterAtoE();
        model.addAttribute("initialA",initialA);
        //initialF
        List<Flight> initialF = flightService.listLetterFtoJ();
        model.addAttribute("initialF",initialF);
        //initialK
        List<Flight> initialK = flightService.listLetterKtoP();
        model.addAttribute("initialK",initialK);
        //initialQ
        List<Flight> initialQ = flightService.listLetterQtoW();
        model.addAttribute("initialQ",initialQ);
        //initialX
        List<Flight> initialX = flightService.listLetterXtoZ();
        model.addAttribute("initialX",initialX);
        return "flight/index";


    }

    @RequestMapping("/search")
    @ResponseBody
    public AjaxResult search(String dstCity,String orgCity,String depTime){
        AjaxResult result = new AjaxResult();
        String arrive_code = dstCity;
        String leave_code = orgCity;
        String query_date = depTime ;
            String search = FlightUtil.search(arrive_code, leave_code, query_date);
            if (search != null) {
                result.setData(search);
            }
        return result;
    }
}
